#include "head.h"

int main(int argc, char *argv[])
{
    int socketfd;
    init_tcp(&socketfd, "192.168.181.128", "8080");

    fd_set set;
    while(1){
        FD_ZERO(&set);
        FD_SET(socketfd, &set);
        int num = select(5, &set, NULL, NULL, NULL);
        //监听客户端连接
        if(FD_ISSET(socketfd, &set)){
            printf("客户端连接\n");
            int net_fd = accept(socketfd, NULL, NULL);
            //----------------------------------------------------------
            //客户端连续三次输入错误密码的标记
            int flag_break = 0;
            //判断客户端能否登录
            login_check(net_fd, &flag_break);
            //标记为1，说明客户端断开连接，关闭客户端的连接，继续下次监听
            if(flag_break == 1){
                printf("关闭客户端连接\n");
                close(net_fd);
                continue;
            }
            //----------------------------------------------------------
            //接收客户端要求下载文件的文件名
            int send_len;
            char send_name[1024] = {0};

            recv(net_fd, &send_len, sizeof(int), MSG_WAITALL);
            printf("%d\n",send_len);
            recv(net_fd, send_name, send_len, MSG_WAITALL);
            printf("%s\n", send_name);

            send_bigfile(net_fd, send_name);
            //recv_bigfile(net_fd, send_name);
            close(net_fd);
        }
    }

    close(socketfd);
    return 0;
}

